-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wai-app-static: use cryptonite instead of cryptohash #519
Conversation
@@ -120,8 +119,8 @@ webAppLookup hashFunc prefix pieces = | |||
-- exists. | |||
hashFile :: FilePath -> IO ByteString | |||
hashFile fp = do | |||
h <- Crypto.Hash.Conduit.hashFile fp | |||
return $ B64.encode $ toBytes (h :: Digest MD5) | |||
f <- BL.readFile fp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has the potential to leak FDs. A better approach would be withBinaryFile
, which will guarantee that the FD is closed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lazy ByteString's readFile
closes the FD ("The Handle will be held open until EOF is encountered"). I've tried withBinaryFile
, it results in hGetBufSome: illegal operation (handle is closed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The correct way to do this is something like:
withBinaryFile fp ReadMode $ \h -> do
lbs <- L.hGetContents h
...
The problem with readFile
rears its head in the case of async exceptions. It's an uncommon case to be sure, but I try to avoid the lazy I/O functions in libraries anyway to prevent confusing behavior.
The Travis build did not pass, can you resolve that before merge? Otherwise, the change seems good to me. |
Works fine now with lower dependency bounds. |
Oh – it was closed because the whole function was lazy. Updated to use |
wai-app-static: use cryptonite instead of cryptohash
Thanks! |
cryptohash
is deprecated in favor ofcryptonite
. Not marked as such on Hackage yet, only on GitHub. Buttls
usescryptonite
already, so these two packages already clash (they export the exact same API).Also,
memory
instead ofbase64-bytestring
for Base64 encoding (memory
is a dependency ofcryptonite
).Yes,
conduit
is also dropped, becausecryptohash-conduit
wasn't updated in a long time, and wasn't ported tocryptonite
. I think it's perfectly fine to use lazy I/O here, for the sake of fewer dependencies.